--pieces
local base = piece("base")
  body = piece("body") 
    local engines = piece("engines")
	  local engine1, engine2 = piece("engine1", "engine2")
    local turrets = {}
      local barrels = {} 
    for i = 1, 8 do
      turrets[i], barrels[i] = piece("turret"..i, "barrel"..i)
    end
    for i = 9, 12 do
      turrets[i], barrels[i] = piece("turret1", "barrel1")
    end

scriptParams = {
  smokePieces = { body },
  enginePieces = { engine1, engine2 },
  smokeDelay = 200,
  maxRockAngleX = 5,
  maxRockAngleZ = 5,
  rockOnMove = true,

  weapons = {}
}

include "pre_scripts.lua"

for i = 1, 13 do
  scriptParams.weapons[i] = {
    turretTurnSpeed = 360, --90,
    sleeveTurnSpeed = 360, --50,
    barrelRecoil = 1,
    minPitch = -20,
    --cegID = 1,
    restores = true,
  }
  local ti = (i - 1) % 8 + 1
  setWeaponPieces(i, turrets[ti],  barrels[ti], barrels[ti], barrels[ti])  
end

include "scripts.lua"


function script.Killed (recentDamage, maxHealth)
  local severity = recentDamage / maxHealth
  
  if (severity <= 0.25) then
    Explode (body, SFX.NONE)
    Explode (engines, SFX.NONE)
    Explode (engine1, SFX.NONE)	
    Explode (engine2, SFX.NONE)
    for i = 1, 8 do	
      Explode (turrets[i], SFX.NONE)
      Explode (barrels[i], SFX.NONE)
    end  	
    return 1
  elseif (severity <= 0.50) then
    Explode (body, SFX.NONE)
    Explode (engines, SFX.NONE)
    Explode (engine1, SFX.SMOKE + SFX.FIRE)	
    Explode (engine2, SFX.SMOKE + SFX.FIRE)
    for i = 1, 8 do	
      Explode (turrets[i], SFX.SMOKE + SFX.FIRE)
      Explode (barrels[i], SFX.SMOKE + SFX.FIRE)
    end  	
    return 2
  else
    Explode (body, SFX.SHATTER)
    Explode (engines, SFX.SHATTER)
    Explode (engine1, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)	
    Explode (engine2, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
    for i = 1, 8 do	
      Explode (turrets[i], SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
      Explode (barrels[i], SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
    end  
    return 3
  end
end